<?php
/*
 * Created on 2011-1-15
 * by lixilei
 */

class ShopBiz{
	
	/**
	 * 获取商家的优惠策略
	 */
	public function getShopStatics($number, $weight){
		$shopDB = spClass("ShopModel", null, MODEL_PATH."ShopModel.php");
		$shop = $shopDB->find(array("shop_id"=>$number), null, "shop_id, name, address");
		if($shop == FALSE){
			return array("ret"=>_FAIL, "errMsg"=>_NUMBER_NOT_EXIST);
		}
		$shopStaticsDB = spClass("ShopStaticsModel", null, MODEL_PATH."ShopStaticsModel.php");
		$statics = $shopStaticsDB->findAll(array("shop_id"=>$number), null, "shop_statics_id, min_weight, max_weight, description, effect, expire");
		if($statics == FALSE){
			return array("ret"=>_FAIL, "errMsg"=>_NO_STATICS);
		}
		// 单一策略
		foreach($statics as $s){
			if(($s["min_weight"] == 0) && ($s["max_weight"] == 0)){
				return array("ret"=>_SUCCESS, "statics"=>($shop + $s));;
			}
			if(($s["min_weight"] <= $weight) && ($s["max_weight"] >= $weight)){
				return array("ret"=>_SUCCESS, "statics"=>($shop + $s));;
			}
		}
		return array("ret"=>_FAIL, "errMsg"=>_NO_MATCH_STATICS);
		// 支持复合策略
//		$staticsTmp = array();
//		foreach($statics as $s){
//			if($s["min_weight"] == 0 && $s["max_weight"] == 0){
//				array_push($staticsTmp, $s);
//			}
//			if($s["min_weight"] <= $weight && $s["max_weight"] >= $weight){
//				array_push($staticsTmp, $s);
//			}
//		}
//		return $shop + $staticsTmp;
	}
}
?>
